<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>注册</title>
	
	<link rel="stylesheet" type="text/css" href="CSS/register.css">
	<script type="text/javascript" src="Js/jquery-2.1.4.min.js"></script>
	<script type="text/javascript">
		$(function()
		{
			$("[name='account']").blur(function()
				{
					var account = $.trim($("[name='account']").val());
					if(account==null||account=="")
					{
						$("#email_notice").html("<font color=\"red\">账号不能为空</font>");
					}
					else if(checkmail(account))
					{
						$("#email_notice").html("");
						$.ajax({
							type:"post",
							url:"<%=basePath%>checkProperty.action",
							data:{propertyName:"account",value:account},
							success:function(data)
							{
								if(data.result=="ok")
								{
									//window.alert("返回 ok");
									$("#email_notice").html("<font color=\"green\">此邮箱可以使用</font>");
									$("[type='submit']").removeAttr("disabled");	
								}
								else
								{
									//window.alert("返回数据 no");
									$("#email_notice").html("<font color=\"red\">此邮箱已被注册</font>");
									$("type='submit']").attr("disabled",true);
								}
							}
						});
					}
					else
					{
						$("#email_notice").html("<font color=\"red\">账号格式不正确</font>");
					}
				}
			);
			
			
			
			$("[name='nickName']").blur(function()
				{
					var nickname = $.trim($("[name='nickName']").val());
					if(nickname==null||nickname=="")
					{
						$("#nickName_notice").html("<font color=\"red\">用户名不能为空</font>");
						$("[type='submit']").addAttr("disabled");
					}
					else
					{
// 					window.alert(nickname);
						$.ajax({
							type:"post",
							url:"<%=basePath%>checkProperty.action",
							data:{propertyName:"nickName",value:nickname},
							success:function(data)
							{
									//window.alert("返回的数据"+data.result);
									if(data.result=="ok")
									{
										//window.alert("返回数据 OK");
										
										$("#nickName_notice").html("<font color=\"green\">用户名可以使用</font>");
										$("[type='submit']").removeAttr("disabled");		
									}
									else
									{
										//window.alert("返回数据 no");
										$("#nickName_notice").html("<font color=\"red\">用户名不可以使用</font>");
										$("type='submit']").attr("disabled",true);
									}
							},
							error:function(jsonmsg){
							
							},
							dataType:"json"
							});
					}
				});
				$("[name='surepwd']").blur(function(){
				var pwd = $("[name='password']").val();
				var surepwd = $("[name='surepwd']").val();
				if(pwd==null || pwd=="")
				{
					$("#pwd_notice").html("<font color=\"red\">密码不能为空</font>");
					$("[type='submit']").attr("disabled",true);
				}
				else if(pwd!=surepwd)
				{
					$("#pwd_notice").html("<font color=\"red\">两次输入的密码不一致</font>");
					$("[type='submit']").attr("disabled",true);
				}
				else
				{
					$("#pwd_notice").html("<font color=\"green\">√</font>");
					$("[type='submit']").removeAttr("disabled");
				}
			});
		});
			
		function checkmail(tmail) 
		{  
			var pattern = /^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,4}$/i;  
		 	if(pattern.test(tmail)) 
		 	{  
		  		return true;  
			}  
		 	else 
		 	{  
		  		return false;  
		 	}  
		} 
		
	</script>

  </head>
  
  <body>
    <div class="topbar-container">
        <div class="topbar">
            <div class="pure-g">
                <div class="pure-u-1-6">
                    <a href="/foodfood/AOHomePage..action" class="logo"><img src="images/logo.png"></a>
                </div>
                <div class="pure-u-2-3">&nbsp;</div>
                <div class="pure-u-1-6 site-nav align-right">已经有账号？<a href="/Kitchen/login.jsp" class="logo">登录</a></div>
            </div>
        </div>
    </div>
	<div class="page-outer">
	    <div class="page-container">
	        <div class="p40 has-top-border has-bottom-border">
	            <div class="page-title align-center pb40"><div class="tittle">注册一个新的账号</div></div>
	            <div class="font14">
	                <form action="<%=basePath %>register.action" method="post">
	                    <div class="email">
	                        <div class="label">邮箱:</div><input type="email" name="account">
	                        <span id="email_notice"></span><br>
	                        
	                    </div>
	                    <div class="email">
	                        <div class="label">用户名:</div><input type="text" name="nickName"><br>
	                        <span id="nickName_notice" ></span>
	                    </div>
	                    <div class="password">
	                        <div class="label">密码:</div><input type="password" name="password"><br>
	                    </div>
	                    <div class="surepassword">
	                        <div class="label">确认密码:</div><input type="password" name="surepwd" >
	                        <span id="pwd_notice"></span><br>
	                    </div>
	                    <%--<div>
	                    	<img id="codeimg" name="codeimg" src="checkcode.jsp" onClick="getvalidateCode(this)">
	                    </div>--%>
	                    <div class="zhuce">
	                        <input type="submit" disabled value="注册">
	                    </div>
	                </form>
	            </div>
	        </div>
	    </div>
	</div>
	</body>
</html>
<script type="text/javascript">
	function getvalidateCode(elem)
	{ 
	       if(!elem){ return false; } 
	       var src = elem.src; 
	       var d = new Date(); 
	       elem.src=src+"?t="+d; 
	 } 
</script>